package com.ruoyi.project.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.project.domain.ExpenseApp;
import com.ruoyi.project.service.IExpenseAppService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 费用申请单信息Controller
 * 
 * @author ruoyi
 * @date 2025-04-04
 */
@RestController
@RequestMapping("/project/app")
public class ExpenseAppController extends BaseController
{
    @Autowired
    private IExpenseAppService expenseAppService;

    /**
     * 查询费用申请单信息列表
     */
    @PreAuthorize("@ss.hasPermi('project:app:list')")
    @GetMapping("/list")
    public TableDataInfo list(ExpenseApp expenseApp)
    {
        startPage();
        List<ExpenseApp> list = expenseAppService.selectExpenseAppList(expenseApp);
        return getDataTable(list);
    }

    /**
     * 导出费用申请单信息列表
     */
    @PreAuthorize("@ss.hasPermi('project:app:export')")
    @Log(title = "费用申请单信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExpenseApp expenseApp)
    {
        List<ExpenseApp> list = expenseAppService.selectExpenseAppList(expenseApp);
        ExcelUtil<ExpenseApp> util = new ExcelUtil<ExpenseApp>(ExpenseApp.class);
        util.exportExcel(response, list, "费用申请单信息数据");
    }

    /**
     * 获取费用申请单信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('project:app:query')")
    @GetMapping(value = "/{appId}")
    public AjaxResult getInfo(@PathVariable("appId") Long appId)
    {
        return success(expenseAppService.selectExpenseAppByAppId(appId));
    }

    /**
     * 新增费用申请单信息
     */
    @PreAuthorize("@ss.hasPermi('project:app:add')")
    @Log(title = "费用申请单信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExpenseApp expenseApp)
    {
        return toAjax(expenseAppService.insertExpenseApp(expenseApp));
    }

    /**
     * 修改费用申请单信息
     */
    @PreAuthorize("@ss.hasPermi('project:app:edit')")
    @Log(title = "费用申请单信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExpenseApp expenseApp)
    {
        return toAjax(expenseAppService.updateExpenseApp(expenseApp));
    }

    /**
     * 删除费用申请单信息
     */
    @PreAuthorize("@ss.hasPermi('project:app:remove')")
    @Log(title = "费用申请单信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{appIds}")
    public AjaxResult remove(@PathVariable Long[] appIds)
    {
        return toAjax(expenseAppService.deleteExpenseAppByAppIds(appIds));
    }
}
